import {actionT} from './actionTypes'
const defaultState = {
    inputValue : 'Write Something',
    list:[
        '早上4点起床，锻炼身体',
        '中午下班游泳一小时'
    ]
}  //默认数据
export default (state = defaultState,action)=>{  //就是一个方法函数
    // state 原始仓库里的状态
    // action 新传递的状态。
    console.log(action.type)
    if(action.type === actionT.changeInput){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state
        newState.inputValue = action.value //Reducer里只能接收state，不能改变state
        return newState
    }
    if(action.type === actionT.addItem){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state 
        // console.log('state',state)
        // console.log('action',action)
        console.log(newState)
        newState.list.push(action.value)
        
        return newState
    }
    if(action.type === actionT.deleteItem){
        let newState = JSON.parse(JSON.stringify(state)) //深度拷贝state 
        newState.list.splice(action.index,1)
        return newState
    }
    if(action.type === actionT.getList){
        let newState = JSON.parse(JSON.stringify(state))
        newState.list=action.value
        // console.log(newState)
        // return newState
        return newState
    }
    return state
}